package cn.cuilan.service;

import com.yunpian.sdk.YunpianException;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import static com.yunpian.sdk.util.HttpUtil.post;

/**
 * 云片发送验证码
 *
 * @author zhangyue
 */
@Service
public class SMSVerifyCodeService {

    private static String URI_SEND_SMS = "https://sms.yunpian.com/v2/sms/single_send.json";
    //TODO 还没有获得apikey 可在官网（http://www.yunpian.com)登录后获取
    private static String API_KEY = "";
    private static String YUN_PIAN_VERIFYTEXT = "【小猪书籍】 您的验证码是";

    public String sendSms(String code, String mobile) throws IOException, YunpianException {
        Map<String, String> params = new HashMap<String, String>();
        params.put("apikey", API_KEY);
        params.put("text", YUN_PIAN_VERIFYTEXT + code);
        params.put("mobile", mobile);
        return post(URI_SEND_SMS, params);
    }

}
